﻿---@diagnostic disable: trailing-space
local extension = Package:new("rfenghou_token", Package.CardPack)
extension.extensionName = "aaa_fenghou"

Fk:loadTranslationTable{
  ["rfenghou_token"] = "封侯衍生牌",
}

local U = require "packages/utility/utility"

--基本牌

local slash = Fk:cloneCard("slash")

local shootSlashSKill = fk.CreateActiveSkill{
  name = "rfenghou_shoot__slash_skill",
  prompt = slash.skill.prompt,
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = function (self, to_select, selected, player, card, distance_limited, extra_data)
    return to_select ~= player.id
  end,
  target_filter = slash.skill.targetFilter,
  on_effect = function (self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if not to.dead then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name
      })
    end
  end
}
Fk:addSkill(shootSlashSKill)

local shoot__slash = fk.CreateBasicCard{
  name = "&rfenghou_shoot__slash",
  skill = shootSlashSKill,
}
extension:addCard(shoot__slash)

Fk:loadTranslationTable{
  ["rfenghou_shoot__slash"] = "射杀",
  [":rfenghou_shoot__slash"] = "基本牌"
  .."<br/><b>时机</b>：出牌阶段限一次"
  .."<br/><b>目标</b>：一名其他角色"
  .."<br/><b>效果</b>：对目标角色造成1点伤害",

  ["rfenghou_shoot__slash_skill"] = "射杀",
}

local shadeSkill = fk.CreateActiveSkill{  --祭祀智慧之不想带江山如故还引用影
  name = "rfenghou__shade_skill",
  can_use = Util.FalseFunc,
}
local shade = fk.CreateBasicCard{
  name = "&rfenghou__shade",
  suit = Card.Spade,
  number = 1,
  skill = shadeSkill,
}
extension:addCard(shade)
Fk:loadTranslationTable{
  ["shade"] = "影",
  ["rfenghou__shade"] = "影",
  [":rfenghou__shade"] = "基本牌<br/><b>效果</b>：没有效果，不能被使用。<br/>当【影】进入弃牌堆后移出游戏。<br/>当一名角色获得【影】时，"..
  "均为从游戏外获得♠A的【影】。",
}

local premeditate = fk.CreateDelayedTrickCard{  --祭祀智慧之不想带江山如故还引用蓄谋
  name = "&rfenghou__premeditate",
}
extension:addCard(premeditate)
Fk:loadTranslationTable{
  ["premeditate"] = "蓄谋",
  ["rfenghou__premeditate"] = "蓄谋",
  [":rfenghou__premeditate"] = "这张牌视为延时锦囊<br/><b>效果：</b>判定阶段开始时，按置入顺序（后置入的先处理）依次处理“蓄谋”牌：1.使用此牌，"..
  "然后此阶段不能再使用此牌名的牌；2.将所有“蓄谋”牌置入弃牌堆。",
}




local old__drugs_skill = fk.CreateActiveSkill{
  name = "old__drugs_skill",
  prompt = "#old__drugs_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.SelfCanUse,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    if to.dead then return end
    if to:isWounded() then
      room:recover { num = 1, skillName = self.name, who = to, recoverBy = room:getPlayerById(effect.from), card = effect.card }
      if to.dead then return end
      room:addPlayerMark(to, "@drugsInflicted")
    end
    if not to:isWounded() then
      room:addPlayerMark(to, "@drugsCaused")
    end
  end
}

local old__drugs = fk.CreateBasicCard{
  name = "&old__drugs",
  suit = Card.Club,
  number = 1,
  skill = old__drugs_skill,
} 

extension:addCards({
  old__drugs
})

Fk:loadTranslationTable{
  ["old__drugs"] = "散",
	[":old__drugs"] = "基本牌（衍生牌）<br /><b>时机</b>：出牌阶段<br /><b>目标：</b>你<br /><b>效果：</b>若你已受伤，回复1点体力且下次受到的伤害+1。若你未受伤，或因此回复至满血，下次造成伤害+1。",
  ["old__drugs_skill"] = "散",
  ["#old__drugs_skill"] = "已受伤：回复体力且下次受到伤害+1；未受伤/因此回满血：下次造成伤害+1",
  ["@drugsCaused"] = "散:造伤+",
}

local diceSkill = fk.CreateActiveSkill{
  name = "rfenghou__dice_skill",
  can_use = Util.FalseFunc,
}
local dice = fk.CreateBasicCard{
  name = "&dice",
  suit = Card.Spade,
  number = 1,
  skill = diceSkill,
}
extension:addCard(dice)
Fk:loadTranslationTable{
  ["dice"] = "骰",
  [":dice"] = "基本牌<br/><b>效果</b>：没有效果，仅用于丢骰子。",
}


local generalcard_skill = fk.CreateActiveSkill{
  name = "generalcard_skill",
  prompt = "#generalcard_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.SelfCanUse,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    if to.dead or not effect.card then return end
    local general = effect.card:getMark("generalcard")
    if general == nil or general == 0 or general == "" then return end
    room:setCardMark(effect.card, "@generalcard", 0)
    room:setCardMark(effect.card, "generalcard", 0)
    room:moveCardTo(effect.card, Card.Void, nil, fk.ReasonJustMove, self.name)
    local choice = "mainGeneral"
    -- 如果主将是士兵，锁定替换主将
    if to.general ~= "blank_nvshibing" and to.general ~= "blank_shibing" then
      choice = room:askForChoice(to, {"mainGeneral",  "deputyGeneral"}, self.name, "#generalcard-choice:::"..general)
    end
    local deputy = choice == "deputyGeneral"
    room:changeHero(to, general, false, deputy, true, false, true)
  end
}

local generalcard = fk.CreateBasicCard{
  name = "&generalcard",
  suit = Card.NoSuit,
  number = 0,
  skill = generalcard_skill,
} 

extension:addCards({
  generalcard,
})

Fk:loadTranslationTable{
  ["generalcard"] = "将",
	[":generalcard"] = "基本牌<br /><b>时机</b>：出牌阶段<br /><b>目标：</b>你<br /><b>效果：</b>用此牌记录的武将替换你的主将或副将。",
  ["generalcard_skill"] = "将",
  ["#generalcard_skill"] = "用记录武将替换你的武将或副将",
  ["@generalcard"] = "",
  ["#generalcard-choice"] = "请用 %arg 替换你的武将或副将！",
}



local peng_skill = fk.CreateActiveSkill{
  name = "peng_skill",
  prompt = "#peng_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = function(self, player, card, extra_data)
    if player:prohibitUse(card) then return end
    return (extra_data and extra_data.bypass_times) or player.phase ~= Player.Play or
      table.find(Fk:currentRoom().alive_players, function(p)
        return self:withinTimesLimit(player, Player.HistoryPhase, card, "peng", p)
      end)
  end,
  mod_target_filter = function(self, to_select, selected, from, card, distance_limited)
    local player = Fk:currentRoom():getPlayerById(to_select)
    return from ~= player and (from:getNextAlive() == player or player:getNextAlive() == from)
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data, player)
    if not Util.TargetFilter(self, to_select, selected, _, card, extra_data, player) then return end
    local target = Fk:currentRoom():getPlayerById(to_select)
    return self:modTargetFilter(to_select, selected, player, card, false) and
    (
      #selected > 0 or
      Self.phase ~= Player.Play or
      (extra_data and extra_data.bypass_times) or
      self:withinTimesLimit(player, Player.HistoryPhase, card, "peng", target)
    )
  end,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if to.dead then return end
    if not to:isNude() and not (effect.disresponsive or table.contains(effect.disresponsiveList or Util.DummyTable, to.id)) then
      local cards = room:askForCard(to, 1, 1, true, self.name, true, nil, "#peng_skill-card")
      if #cards > 0 then
        room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
        local put = room:getSubcardsByRule(effect.card, {Card.Processing})
        if #put > 0 then
          room:moveCardTo(put, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
        end
        return
      end
    end
    room:loseHp(to, 1, self.name)
  end
}

local peng = fk.CreateBasicCard{
  name = "&peng",
  suit = Card.Spade,
  number = 12,
  skill = peng_skill,
  is_damage_card = true, -- 失去体力算伤害牌吗？
} 

extension:addCards({
  peng,
  peng:clone(Card.Diamond, 12),
  peng:clone(Card.Heart, 12),
  peng:clone(Card.Club, 12),
})


Fk:loadTranslationTable{
  ["peng"] = "嘭！",
	[":peng"] = "基本牌<br /><b>时机</b>：出牌阶段限一次<br /><b>目标：</b>你邻家<br /><b>效果：</b>目标角色须将一张牌与此【嘭！】置于牌堆顶，或失去1点体力。",
  ["peng_skill"] = "嘭！",
  ["#peng_skill"] = "令一个邻家选择将1牌置于牌堆顶或失去1体力",
  ["#peng_skill-card"] = "请将一张牌与此【嘭！】置于牌堆顶，否则失去1点体力",
}



-- 搬运手杀衍生牌【奇正相生】

local raidAndFrontalAttackSkill = fk.CreateActiveSkill{
  name = "rfenghou__raid_and_frontal_attack_skill",
  can_use = Util.CanUse,
  target_filter = Util.TargetFilter,
  target_num = 1,
  prompt = "#raid_and_frontal_attack_skill",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user.id ~= to_select
  end,
  on_effect = function(self, room, effect)
    local cardResponded = room:askForResponse(room:getPlayerById(effect.to), "rfenghou__raid_and_frontal_attack", "slash,jink", "#RFA-response:" .. effect.from, true, nil, effect)

    if cardResponded then
      room:responseCard({
        from = effect.to,
        card = cardResponded,
        responseToEvent = effect,
      })
    end

    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)

    local RFAChosen = (effect.extra_data or {}).RFAChosen or "RFA_raid"
    if not (cardResponded and cardResponded.trueName == (RFAChosen == "RFA_frontal" and "jink" or "slash")) then
      if RFAChosen == "RFA_raid" then
        room:damage({
          from = from,
          to = to,
          card = effect.card,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      else
        if not to:isNude() and not from.dead then
          local cardId = room:askForCardChosen(from, to, "he", self.name)
          room:obtainCard(from, cardId, room:getCardArea(cardId) == Player.Equip, fk.ReasonPrey, from.id, self.name)
        end
      end
    end
  end
}

local raidAndFrontalAttackSkillChoose = fk.CreateTriggerSkill{
  name = "rfenghou__raid_and_frontal_attack_choose",
  global = true,
  priority = 0, -- game rule
  events = { fk.TargetSpecified },
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.name == "rfenghou__raid_and_frontal_attack"
  end,
  on_trigger = function(self, event, target, player, data)
    local choice = player.room:askForChoice(player, { "RFA_frontal", "RFA_raid" }, "rfenghou__raid_and_frontal_attack", "#RFA-choose::" .. data.to)
    data.extra_data = data.extra_data or {}
    data.extra_data.RFAChosen = choice
  end,
}
Fk:addSkill(raidAndFrontalAttackSkillChoose)

local raidAndFrontalAttack = fk.CreateTrickCard{
  name = "&rfenghou__raid_and_frontal_attack",
  suit = Card.Spade,
  number = 2,
  is_damage_card = true,
  skill = raidAndFrontalAttackSkill,
}
Fk:loadTranslationTable{
  ["raid_and_frontal_attack"] = "奇正相生",
  ["rfenghou__raid_and_frontal_attack"] = "奇正相生",
  [":rfenghou__raid_and_frontal_attack"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名其他角色<br/><b>效果</b>：当此牌指定目标后，你为其指定“奇兵”或“正兵”。目标角色可以打出一张【杀】或【闪】，然后若其为：“奇兵”目标且未打出【杀】，你对其造成1点伤害；“正兵”目标且未打出【闪】，你获得其一张牌。",
  ["rfenghou__raid_and_frontal_attack_skill"] = "奇正相生",
  ["#raid_and_frontal_attack_skill"] = "选择一名其他角色并选择一项。正兵：不出闪则获得其牌；奇兵：不出杀则受伤害",
  ["RFA_raid"] = "奇兵",
  ["RFA_frontal"] = "正兵",
  ["#RFA-response"] = "正兵：未出闪，%src获得你牌；奇兵：未出杀，你受到其伤害",
  ["#RFA-choose"] = "正兵：%dest不出闪，你获得其牌；奇兵：其不出杀，其受到伤害",
}

extension:addCards({
  raidAndFrontalAttack,
  --raidAndFrontalAttack:clone(Card.Spade, 4),
  --raidAndFrontalAttack:clone(Card.Spade, 6),
  --raidAndFrontalAttack:clone(Card.Spade, 8),

  --raidAndFrontalAttack:clone(Card.Club, 3),
  --raidAndFrontalAttack:clone(Card.Club, 5),
  --raidAndFrontalAttack:clone(Card.Club, 7),
  --raidAndFrontalAttack:clone(Card.Club, 9),
})



-- 搬运自OL活动场神武再世，替换【借刀杀人】
local artfulGraftSkill = fk.CreateActiveSkill{
  name = "artful_graft_skill",
  prompt = "#artful_graft_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, player, card)
    return to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if to.dead then return end
    local use = room:askForUseCard(to, "slash", "slash", "#artful_graft-slash:"..player.id, true, nil, effect)
    if use then
      use.extraUse = true
      room:useCard(use)
    elseif not player.dead and not to:isNude() then
      local cards = to:getCardIds("he")
      if #cards > 2 then
        cards = room:askForCard(to, 2, 2, true, self.name, false, nil, "#artful_graft-give:"..player.id)
      end
      room:obtainCard(player, cards, false, fk.ReasonGive, to.id, self.name)
    end
  end
}
local artful_graft = fk.CreateTrickCard{
  name = "&artful_graft",
  skill = artfulGraftSkill,
}
extension:addCard(artful_graft)
Fk:loadTranslationTable{
  ["artful_graft"] = "移花接木",
  ["artful_graft_skill"] = "移花接木",
  [":artful_graft"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名有牌的其他角色<br/><b>效果</b>：目标角色需使用一张【杀】，否则交给你两张牌。",
  ["#artful_graft-slash"] = "移花接木：请使用一张【杀】，否则你须交给 %src 两张牌。",
  ["#artful_graft-give"] = "移花接木：你须交给 %src 两张牌。",
  ["#artful_graft_skill"] = "令目标选择使用杀或交出2牌",
}


-- 搬运自OL活动场神武再世，替换【借刀杀人】
local CarryForwardSkill = fk.CreateActiveSkill{
  name = "carry_forward_skill",
  prompt = "#carry_forward_skill",
  can_use = Util.SelfCanUse,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if player.dead then return end
    local cards = player:getCardIds("h")
    if #cards == 0 then return end
    local names = table.filter(U.getAllCardNames("t"), function (name)
      return not Fk:cloneCard(name).is_passive
    end)
    local use = U.askForUseVirtualCard(room, player, names, cards, self.name, "#carry_forward-use", true, true, false, true)
    if not use then
      cards = table.filter(cards, function (id) return not player:prohibitDiscard(id) end)
      if #cards > 0 then
        room:throwCard(cards, self.name, player, player)
        if not player.dead then
          player:drawCards(#cards, self.name)
        end
      end
    end
  end
}
local carry_forward = fk.CreateTrickCard{
  name = "&carry_forward",
  skill = CarryForwardSkill,
  suit = Card.Spade,
  number = 6,
}
extension:addCards{carry_forward, carry_forward:clone(Card.Heart, 6)}
Fk:loadTranslationTable{
  ["carry_forward"] = "继往开来",
  ["carry_forward_skill"] = "继往开来",
  [":carry_forward"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：选择一项：1.弃置所有手牌，然后摸等量的牌；2.将所有手牌当任意普通锦囊牌使用。",
  ["#carry_forward-use"] = "请选择一个锦囊牌名，将所有手牌当此牌使用，若不使用，则弃置之并摸等量牌",
  ["#carry_forward_skill"] = "将所有手牌弃置并摸等量牌，或当任意普通锦囊牌使用",
}





local cicada_temples_skill = fk.CreateTriggerSkill{
  name = "#cicada_temples_skill",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    for _, id in ipairs(player:getCardIds("e")) do
      local card = Fk:getCardById(id)
      if card.name == "cicada_temples" then
        player:drawCards(math.min(card:getMark("cicada_temples_count") + 1, 3), self.name)
        if player.dead then break end
      end
    end
  end,

  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    return table.find(player:getCardIds("e"), function (id)
      return Fk:getCardById(id).name == "cicada_temples"
    end)
  end,
  on_refresh = function(self, event, target, player, data)
    for _, id in ipairs(player:getCardIds("e")) do
      local card = Fk:getCardById(id)
      if card.name == "cicada_temples" then
        player.room:setCardMark(card, "cicada_temples_count", card:getMark("cicada_temples_count") + 1)
      end
    end
  end,
}
Fk:addSkill(cicada_temples_skill)

local cicada_temples = fk.CreateTreasure{
  name = "&cicada_temples",
  suit = Card.Club,
  number = 12,
  equip_skill = cicada_temples_skill,
  ---@param room Room
  on_uninstall = function(self, room, player)
    Treasure.onUninstall(self, room, player)
    room:setCardMark(self, "cicada_temples_count", 0)
  end,
}
extension:addCard(cicada_temples)

Fk:loadTranslationTable{
  ["cicada_temples"] = "蝉鬓",
  [":cicada_temples"] = "装备牌·宝物（衍生牌）<br/><b>宝物技能</b>：锁定技，结束阶段，你摸X张牌（X为此牌进入你装备区后经过的回合数，至多为3）。此牌进入弃牌堆后销毁。",
  ["#cicada_temples_skill"] = "蝉鬓",
}


local breastplateSkill = fk.CreateTriggerSkill{
  name = "#rfenghou__breastplate_skill",
  attached_equip = "rfenghou__breastplate",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.damage >= player.hp
    -- 防一手虚拟装备
    and table.find(player:getEquipments(Card.SubtypeArmor), function(id) return Fk:getCardById(id).name == "rfenghou__breastplate" end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#rfenghou__breastplate-ask:::" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name, "defensive")
    room:sendLog{
      type = "#BreastplateSkill",
      from = player.id,
      arg = self.attached_equip,
      arg2 = data.damage,
      arg3 = Fk:getDamageNatureName(data.damageType),
    }
    room:moveCardTo(table.filter(player:getEquipments(Card.SubtypeArmor), function(id) return Fk:getCardById(id).name == "rfenghou__breastplate" end),
      Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
    return true
  end,
}
Fk:addSkill(breastplateSkill)
local breastplate = fk.CreateArmor{
  name = "&rfenghou__breastplate",
  suit = Card.Club,
  number = 2,
  equip_skill = breastplateSkill,
}
extension:addCard(breastplate)

Fk:loadTranslationTable{
  ["breastplate"] = "护心镜",
  ["rfenghou__breastplate"] = "护心镜",
  ["#rfenghou__breastplate_skill"] = "护心镜",
  [":rfenghou__breastplate"] = "装备牌·防具<br/><b>防具技能</b>：当你受到伤害时，若此伤害大于或等于你当前的体力值，你可将装备区里的【护心镜】置入弃牌堆，然后防止此伤害。",
  ["#rfenghou__breastplate-ask"] = "护心镜：你可将装备区里的【护心镜】置入弃牌堆，防止 %arg 点 %arg2 伤害",
  ["#BreastplateSkill"] = "%from 发动了〖%arg〗，防止了 %arg2 点 %arg3 伤害",
}


-- 以撒包“堕化遗骸”的衍生牌，空技能
local ForgottenSkill = fk.CreateTriggerSkill{
  name = "#forgottencard_skill",
  attached_equip = "forgottencard",
}
Fk:addSkill(ForgottenSkill)
local forgottencard = fk.CreateArmor{
  name = "&forgottencard",
  suit = Card.Spade,
  number = 1,
  equip_skill = ForgottenSkill,
}
-- 禁止使用此装备牌哈
local noUseEquipSkill = fk.CreateActiveSkill{
  name = "nouse_equip_skill",
  prompt = "",
  mod_target_filter = Util.FalseFunc,
  can_use = Util.SelfCanUse,
}
noUseEquipSkill.cardSkill = true
forgottencard.skill = noUseEquipSkill
extension:addCard(forgottencard)

Fk:loadTranslationTable{
  ["forgottencard"] = "堕化遗骸",
  [":forgottencard"] = "装备牌·防具<br/><b>防具技能</b>：无法使用。当此牌离开手牌区后，令“堕化遗骸”复位并摸两张牌。",
  ["nouse_equip_skill"] = "无法使用",
}


--- 搬运OL蒲元小玩具，来自各种活动场卡牌

local rfenghou_halberd_skill = fk.CreateTriggerSkill{
  name = "#rfenghou_halberd_skill",
  attached_equip = "rfenghou_halberd",
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
    and data.by_user == true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"draw1"}
    if not data.to:isNude() then table.insert(choices, "rfenghou_halberd_throw") end
    if room:askForChoice(player, choices, self.name) == "draw1" then
      player:drawCards(1, self.name)
    else
      local cid = room:askForCardChosen(player, data.to, "he", self.name)
      room:throwCard({cid}, self.name, data.to, player)
    end
  end,
}
Fk:addSkill(rfenghou_halberd_skill)
local rfenghou_halberd = fk.CreateWeapon{
  name = "&rfenghou_halberd",
  suit = Card.Diamond,
  number = 12,
  attack_range = 4,
  equip_skill = rfenghou_halberd_skill,
}
extension:addCard(rfenghou_halberd)
Fk:loadTranslationTable{
  ["rfenghou_halberd"] = "无双方天戟",
  ["#rfenghou_halberd_skill"] = "无双方天戟",
  [":rfenghou_halberd"] = "装备牌·武器<br/><b>攻击范围</b>：4<br/><b>武器技能</b>：你使用【杀】对目标角色造成伤害后，你可以摸一张牌或弃置该角色一张牌。",
  ["rfenghou_halberd_throw"] = "弃置其一张牌",
}


local rfenghou_blood_sword_skill = fk.CreateTriggerSkill{
  name = "#rfenghou_blood_sword_skill",
  attached_equip = "rfenghou_blood_sword",
  frequency = Skill.Compulsory,
  events = { fk.TargetSpecified },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
    room:addPlayerMark(room:getPlayerById(data.to), "rfenghou_blood_swordMark")
    data.extra_data = data.extra_data or {}
    data.extra_data.rfenghou_blood_swordNullified = data.extra_data.rfenghou_blood_swordNullified or {}
    data.extra_data.rfenghou_blood_swordNullified[tostring(data.to)] = (data.extra_data.rfenghou_blood_swordNullified[tostring(data.to)] or 0) + 1
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.rfenghou_blood_swordNullified
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for key, num in pairs(data.extra_data.rfenghou_blood_swordNullified) do
      local p = room:getPlayerById(tonumber(key))
      room:removePlayerMark(p, fk.MarkArmorNullified, num)
      if p:getMark("rfenghou_blood_swordMark") > 0 then
        room:removePlayerMark(p, "rfenghou_blood_swordMark", num)
      end
    end
    data.rfenghou_blood_swordNullified = nil
  end,
}
local rfenghou_blood_sword_prohibit = fk.CreateProhibitSkill{
  name = "#rfenghou_blood_sword_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("rfenghou_blood_swordMark") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id) return table.contains(player:getCardIds(Player.Hand), id) end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("rfenghou_blood_swordMark") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id) return table.contains(player:getCardIds(Player.Hand), id) end)
    end
  end,
}
rfenghou_blood_sword_skill:addRelatedSkill(rfenghou_blood_sword_prohibit)
Fk:addSkill(rfenghou_blood_sword_skill)
local rfenghou_blood_sword = fk.CreateWeapon{
  name = "&rfenghou_blood_sword",
  suit = Card.Spade,
  number = 6,
  attack_range = 2,
  equip_skill = rfenghou_blood_sword_skill,
}
extension:addCard(rfenghou_blood_sword)
Fk:loadTranslationTable{
  ["rfenghou_blood_sword"] = "赤血青锋",
  ["#rfenghou_blood_sword_skill"] = "赤血青锋",
  [":rfenghou_blood_sword"] = "装备牌·武器<br /><b>攻击范围</b>：２<br /><b>武器技能</b>：锁定技，你使用【杀】指定目标后，此【杀】无视目标角色的防具且目标不能使用或打出手牌，直至此【杀】结算完毕。",
}














--- FIXEME: 此乃【晋】桓温的技能【行将】，等技能动态描述能改技能名再说
--- 请保证这个技能最后加载

local names = {}
for name, _ in pairs(Fk.all_card_types) do
  table.insertIfNeed(names, name)
end
for _, card in ipairs(extension.cards) do
  table.insertIfNeed(names, card.name)
end

for _, name in ipairs(names) do
  local nameZh = Fk:translate(name, "zh_CN")
  local nameAbbr = nameZh
  local len = nameAbbr:len()
  if len == 1 then
    nameAbbr = "印"..nameAbbr
  elseif len > 2 then
    nameAbbr = string.sub(nameAbbr, 1, 6)
  end
  local desc = "每轮限一次，你可以视为使用【"..nameZh.."】。"
  local xingjiangSkill = fk.CreateViewAsSkill{
    name = "rfenghou__xingjiang_"..name,
    pattern = ".|.|.|.|"..name,
    card_filter = Util.FalseFunc,
    prompt = desc,
    view_as = function(self)
      local c = Fk:cloneCard(self.name:gsub("rfenghou__xingjiang_", ""))
      c.skillName = self.name
      -- 印的牌莫名其妙变成黑色，不知道为啥，故如此做
      c.color = Card.NoColor
      c.suit = Card.NoSuit
      c.number = 0
      return c
    end,
    before_use = function (self, player, use)
      player:broadcastSkillInvoke("rfenghou__xingjiang")
    end,
    enabled_at_play = function(self, player)
      return player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    end,
    enabled_at_response = function (self, player, response)
      return not response and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    end,
    on_lose = function (self, player)
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
    end,
  }
  Fk:addSkill(xingjiangSkill)
  
  Fk:loadTranslationTable{
    [xingjiangSkill.name] = nameAbbr,
    [":"..xingjiangSkill.name] = desc,
  }
end

-- 标准卡牌、封侯卡牌外的印不了，只能这样干
local modalWord = {"啥", "这", "那", "吧", "哈", "哦", "啊", "呀", "呃", "呢", "嘛", "吗", "嘿", "哼", "哎", "唉", "哟", "哇", "哩", "咯"}
for i, word in ipairs(modalWord) do
  local nameZh = "印"..word
  local xingjiangSkill = fk.CreateViewAsSkill{
    name = "rfenghou__xingjiang_"..i,
    pattern = ".",
    card_filter = Util.FalseFunc,
    prompt = function (self)
      local name = Self:getMark(self.name)
      if name ~= 0 then
        return "每轮限一次，你可以视为使用【"..Fk:translate(name).."】。"
      end
      return ""
    end,
    view_as = function(self, _, player)
      local name = player:getMark(self.name)
      if name == 0 then return nil end
      local c = Fk:cloneCard(name)
      c.skillName = self.name
      return c
    end,
    before_use = function (self, player, use)
      player:broadcastSkillInvoke("rfenghou__xingjiang")
    end,
    enabled_at_play = function(self, player)
      if player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
        local name = player:getMark(self.name)
        if name ~= 0 then
          local card = Fk:cloneCard(name)
          card.skillName = self.name
          return player:canUse(card) and not player:prohibitUse(card)
        end
      end
    end,
    enabled_at_response = function (self, player, response)
      if not response and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 and Fk.currentResponsePattern then
        local name = player:getMark(self.name)
        if name ~= 0 then
          return Exppattern:Parse(Fk.currentResponsePattern):matchExp(".|.|.|.|"..name)
        end
      end
    end,
    on_lose = function (self, player)
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
      player.room:setPlayerMark(player, self.name, 0)
    end,
    dynamic_desc = function (self, player, lang)
      local name = player:getMark(self.name)
      if name ~= 0 then
        return self.name.."_dyn:"..player:getMark(self.name)
      end
      return self.name
    end,
  }
  Fk:addSkill(xingjiangSkill)
  
  Fk:loadTranslationTable{
    [xingjiangSkill.name] = nameZh,
    [":"..xingjiangSkill.name] = "每轮限一次，你可以视为使用【？】。",
    [":"..xingjiangSkill.name.."_dyn"] = "每轮限一次，你可以视为使用【{1}】。",
  }

end



return extension
